home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / lang_ext / vbawk / detab.usr next >
Encoding:
Text File  |  1994-08-14  |  2.1 KB  |  66 lines

  1. Global Const HIGHEST_TAB = 100
  2. Global Tabstops(-1 To HIGHEST_TAB) As Integer    'tab stops array
  3. Global NumTabStops As Integer      'number of tab stops in array
  4.  
  5. 'This routine is called after each file is closed and
  6. 'all processing for that file is finished.
  7. Sub AfterAFile ()
  8. End Sub
  9.  
  10. 'This routine is called at the very end of the program,
  11. 'after all files have been processed.
  12. Sub AfterAllFiles ()
  13. End Sub
  14.  
  15. 'The return value of BeforeAFile is usually True, which
  16. 'indicates that the current file is to be processed
  17. 'normally.  By returning False, you can skip processing
  18. 'the current file.
  19. Function BeforeAFile ()
  20.     BeforeAFile = True
  21. End Function
  22.  
  23. 'This routine is executed at the very beginning of the
  24. 'application, before any files are opened or any
  25. 'processing has taken place.
  26. Function BeforeAllFiles () As Integer
  27.     APPNAME = "Detabbing Utility"
  28.     Tabstops(-1) = 1
  29.     SetTabStops.Show 1
  30.     If SetTabStops.Tag = "CANCEL" Then
  31.         BeforeAllFiles = False
  32.     Else
  33.         BeforeAllFiles = True
  34.     End If
  35. End Function
  36.  
  37. 'This routine is called over and over, each time being
  38. 'passed a succeeding line of the file being
  39. 'processed.  Or, in binary mode, this routine is passed
  40. 'a chunk of bytes as long as RECLEN, except for the
  41. 'final chunk which may be smaller than RECLEN.
  42. Function DoALine (TheLine As String) As Integer
  43.     Dim TabIndex As Integer     'index tab was found at
  44.     Dim NumBlanks As Integer    'number of blanks to insert for this tab
  45.  
  46.     TabIndex = InStr(1, TheLine, Chr$(9))
  47.     While TabIndex <> 0
  48.         NumBlanks = FigureNumBlanks(TabIndex)
  49.         TheBlanks$ = String$(NumBlanks, " ")
  50.         Substitute TheLine, TabIndex, 1, TheBlanks$
  51.         TabIndex = InStr((TabIndex + NumBlanks), TheLine, Chr$(9))
  52.     Wend
  53.     DoALine = True
  54. End Function
  55.  
  56. Function FigureNumBlanks (TabNdx As Integer) As Integer
  57.     FigureNumBlanks = 0
  58.     For i% = -1 To NumTabStops - 1
  59.         If TabNdx >= Tabstops(i%) And TabNdx < Tabstops(i% + 1) Then
  60.             FigureNumBlanks = Tabstops(i% + 1) - TabNdx
  61.             Exit Function
  62.         End If
  63.     Next i%
  64. End Function
  65.  
  66.